package br.com.werp.suporte.Geral;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.egen.util.jdbc.*;
import com.egen.util.text.*;

/**
 * Creation Date 26/10/2005 15:37:04
 * Last Modify Date 22/03/2007 16:47:47
 */

public class MensagemAction extends com.egen.util.struts.AbstractAction {

  public ActionForward perform_compor_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {


      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              com.egen.util.system.Error.getMessage(e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          com.egen.util.system.Error.getDescription(e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

  public ActionForward perform_resetfull_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //----------------------------------------------------------------------
      br.com.werp.regras.geral.Mensagem mensagem =
        br.com.werp.regras.geral.FabricaSubSistema.getMensagem();
      String usur_login = (String) session.getAttribute("j_username");
      if (usur_login == null) {
        usur_login = request.getParameter("usur_login");
        session.setAttribute("j_username",usur_login);
      }
      session.setAttribute("mensagens_novas",
          mensagem.pesqusiarMensagemNova(usur_login));
      session.setAttribute("caixa_saida",new ArrayList());
      session.setAttribute("pesquisa_mensagens", new ArrayList());
      //----------------------------------------------------------------------
      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              com.egen.util.system.Error.getMessage(e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          com.egen.util.system.Error.getDescription(e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

  public ActionForward perform_pesquisar_saida_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //----------------------------------------------------------------------
      br.com.werp.regras.geral.Mensagem mensagem =
        br.com.werp.regras.geral.FabricaSubSistema.getMensagem();
      session.setAttribute("caixa_saida",
          mensagem.pesqusiarCaixaSaida(
            (String) session.getAttribute("j_username"), form));
      //----------------------------------------------------------------------

      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              com.egen.util.system.Error.getMessage(e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          com.egen.util.system.Error.getDescription(e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

  public ActionForward perform_pesquisar_entrada_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //----------------------------------------------------------------------
      br.com.werp.regras.geral.Mensagem mensagem =
        br.com.werp.regras.geral.FabricaSubSistema.getMensagem();
      session.setAttribute("pesquisa_mensagens",
          mensagem.pesquisarMensagensEntrada(
            (String) session.getAttribute("j_username"), form));
      //----------------------------------------------------------------------

      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              com.egen.util.system.Error.getMessage(e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          com.egen.util.system.Error.getDescription(e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

}
